define(()=>{
    return function(){
        class TaobaoSearch{
            constructor(){
                this.search = document.getElementById("search");
                this.searchList = document.querySelector(" #headSearchBox .main.flex-c-between .headerSearch .searchList");
                this.url = "https://suggest.taobao.com/sug";
                this.addEvent()
            }
            addEvent(){
                const that = this;
                this.search.oninput = function(){
                    that.searchList.style.display="block"
                    that.key = this.value;
                    that.jsonp();
                }
                this.search.onblur=function(){
                    that.searchList.style.display="none"
                }
            }
            jsonp(){
                const that = this;
                window.xeh = function(res){
                    that.msg = res.result;
                    that.createList()
                }
                const s = document.createElement("script");
                this.url = this.url + "?" + this.objTquery();
                s.src = this.url;
                document.body.appendChild(s);
            }
            objTquery(){
                const data = {
                    k: 1,
                    area: "c2c",
                    q: this.key,
                    code: "utf-8",
                    ts: 1652512732893,
                    callback: "xeh"
                }
                let str = ""
                for(let i in data){
                    str += `${i}=${data[i]}&`;
                }
                return str.slice(0,-1);
            }
            createList(){
                let str = "";
                this.msg.forEach(val=>{
                    str += `<li>${val[0]}</li>`
                })
                this.searchList.innerHTML = str;
            }
        }
        new TaobaoSearch();
    
    }
});